<template>
	<div>
		<cl-form ref="add-type"></cl-form>
	</div>
</template>

<script>
export default {
	data() {
		return {};
	},

	mounted() {},

	methods: {
		async fatchList() {
			let categoryList = await this.$service.FAQMenagement.faqCategory.list();
			console.log(categoryList);
			this.$emit('new-type', categoryList);
		},
		selectType() {
			this.$refs['add-type'].open({
				props: {
					title: '新建类型',
					'label-width': '100px',
					width: '482px'
				},
				items: [
					{
						prop: 'name',
						label: '问题类型',
						component: {
							name: 'el-input',
							attrs: {
								placeholder: '问题类型名称'
							}
						},
						rules: {
							required: true,
							message: '问题类型名称'
						}
					},
					{
						label: '图标',
						prop: 'icon',
						component: {
							name: 'cl-upload'
						},
						rules: {
							required: false,
							message: '图标'
						}
					},
					{
						label: '是否启用',
						prop: 'status',
						value: true,
						component: {
							name: 'el-switch'
						}
					}
				],
				on: {
					submit: ({ data, close, done }) => {
						this.$service.FAQMenagement.faqCategory
							.add({
								...data,
								status: data.status ? 1 : 0
							})
							.then(() => {
								this.$message.success('添加成功');
								this.fatchList();
								close();
							})
							.catch(err => {
								this.$message.error(err);
								done();
							});
					}
				}
			});
		}
	}
};
</script>
<style lang="stylus" scoped></style>
